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

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

k = A("k")
e = B("e")
f = A("f")
j = A("j")

k.r = j
e.q = k
e.p = k
f.r = k
j.r = k
assert e.p.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.q: A = None
        self.p: A = None
        self.txt = txt

k = A("k")
e = B("e")
f = A("f")
j = A("j")

k.r = j
e.q = k
e.p = k
f.r = k
j.r = k
assert e.p.r.r.txt == "k"