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

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

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

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

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

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

g.z = a
l.p = a
l.r = a
a.p = l
a.r = l
assert a.p.r.p.txt == "l"