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

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

g.p = i
i.u = a
a.p = i
assert a.p.u.p.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

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

g.p = i
i.u = a
a.p = i
assert a.p.u.p.txt == "i"