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

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

b = A("b")
d = B("d")
a = A("a")
j = B("j")
k = A("k")
g = B("g")
c = B("c")

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

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

b = A("b")
d = B("d")
a = A("a")
j = B("j")
k = A("k")
g = B("g")
c = B("c")

b.t = j
b.x = a
d.z = j
d.x = b
a.t = c
a.x = k
j.z = c
j.x = b
k.t = d
k.x = b
g.z = j
g.x = k
c.z = g
c.x = b
assert c.x.t.z.x.txt == "b"