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

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

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

c = A("c")
e = B("e")
j = C("j")
b = A("b")

c.r = b
c.q = j
e.r = b
e.q = c
j.z = c
b.r = c
b.q = j
assert j.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.q: C = None
        self.txt = txt

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

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

c = A("c")
e = B("e")
j = C("j")
b = A("b")

c.r = b
c.q = j
e.r = b
e.q = c
j.z = c
b.r = c
b.q = j
assert j.z.q.z.txt == "c"