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

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

d = A("d")
b = B("b")
j = A("j")
a = B("a")
k = B("k")
i = B("i")

d.z = j
d.t = i
b.q = d
b.x = a
j.z = d
j.t = i
a.q = j
a.x = k
k.q = d
k.x = a
i.q = j
i.x = k
assert j.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.t: B = None
        self.txt = txt

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

d = A("d")
b = B("b")
j = A("j")
a = B("a")
k = B("k")
i = B("i")

d.z = j
d.t = i
b.q = d
b.x = a
j.z = d
j.t = i
a.q = j
a.x = k
k.q = d
k.x = a
i.q = j
i.x = k
assert j.z.z.z.txt == "d"