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

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

e = A("e")
i = B("i")
g = B("g")

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

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

e = A("e")
i = B("i")
g = B("g")

e.r = i
i.t = g
g.t = i
assert i.t.t.t.txt == "g"