class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

h = A("h")
n = B("n")
b = A("b")
c = A("c")
k = A("k")
d = A("d")
j = A("j")
i = A("i")

h.x = n
h.s = j
n.y = i
b.x = n
b.s = j
c.x = n
c.s = b
k.x = n
k.s = d
d.x = n
d.s = k
j.x = n
j.s = i
i.x = n
i.s = d
assert h.x.y.x.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.s: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

h = A("h")
n = B("n")
b = A("b")
c = A("c")
k = A("k")
d = A("d")
j = A("j")
i = A("i")

h.x = n
h.s = j
n.y = i
b.x = n
b.s = j
c.x = n
c.s = b
k.x = n
k.s = d
d.x = n
d.s = k
j.x = n
j.s = i
i.x = n
i.s = d
assert h.x.y.x.y.x.txt == "n"