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.q: A = None
        self.txt = txt

c = A("c")
a = B("a")
j = B("j")
m = B("m")
i = B("i")
d = B("d")
h = A("h")
f = B("f")

c.t = h
c.z = j
a.q = c
j.q = c
m.q = h
i.q = h
d.q = c
h.t = c
h.z = j
f.q = h
assert d.q.z.q.z.q.t.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.q: A = None
        self.txt = txt

c = A("c")
a = B("a")
j = B("j")
m = B("m")
i = B("i")
d = B("d")
h = A("h")
f = B("f")

c.t = h
c.z = j
a.q = c
j.q = c
m.q = h
i.q = h
d.q = c
h.t = c
h.z = j
f.q = h
assert d.q.z.q.z.q.t.txt == "h"