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

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

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

l.p = k
l.r = k
g.x = l
g.v = k
k.p = l
k.r = l
assert k.p.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: A = None
        self.txt = txt

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

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

l.p = k
l.r = k
g.x = l
g.v = k
k.p = l
k.r = l
assert k.p.p.r.txt == "l"