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

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

g = A("g")
d = B("d")
a = A("a")
c = B("c")
m = B("m")
j = A("j")

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

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

g = A("g")
d = B("d")
a = A("a")
c = B("c")
m = B("m")
j = A("j")

g.t = d
d.s = j
d.z = c
a.t = d
c.s = j
c.z = d
m.s = g
m.z = c
j.t = c
assert d.z.z.s.txt == "j"