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

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

g = A("g")
b = B("b")
k = B("k")
a = A("a")

g.r = a
b.p = g
b.u = k
k.p = a
k.u = b
a.r = g
assert b.p.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

g = A("g")
b = B("b")
k = B("k")
a = A("a")

g.r = a
b.p = g
b.u = k
k.p = a
k.u = b
a.r = g
assert b.p.r.r.r.txt == "a"