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

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

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

e.p = l
l.u = g
g.p = l
assert l.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

e.p = l
l.u = g
g.p = l
assert l.u.p.u.txt == "g"