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

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

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

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

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

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

d.t = b
b.r = e
j.t = b
e.r = b
assert b.r.r.r.txt == "e"