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

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

g = A("g")
e = B("e")
b = B("b")
d = B("d")
j = A("j")

g.y = b
e.t = b
b.t = d
d.t = e
j.y = d
assert d.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

g = A("g")
e = B("e")
b = B("b")
d = B("d")
j = A("j")

g.y = b
e.t = b
b.t = d
d.t = e
j.y = d
assert d.t.t.t.txt == "d"