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

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

h = A("h")
d = B("d")
e = B("e")
i = B("i")
c = B("c")
g = B("g")
n = A("n")
a = B("a")

h.t = n
h.z = g
d.x = i
e.x = g
i.x = c
c.x = d
g.x = c
n.t = h
n.z = d
a.x = e
assert i.x.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.z: B = None
        self.txt = txt

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

h = A("h")
d = B("d")
e = B("e")
i = B("i")
c = B("c")
g = B("g")
n = A("n")
a = B("a")

h.t = n
h.z = g
d.x = i
e.x = g
i.x = c
c.x = d
g.x = c
n.t = h
n.z = d
a.x = e
assert i.x.x.x.x.x.x.x.x.txt == "d"