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.z: A = None
        self.txt = txt

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

g.p = a
e.u = i
e.z = g
a.u = i
a.z = g
i.p = a
assert e.z.p.z.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.z: A = None
        self.txt = txt

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

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