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

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

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

j = A("j")
d = B("d")
m = C("m")
k = A("k")

j.r = m
j.p = m
d.u = m
m.q = d
k.r = m
k.p = m
assert m.q.u.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.p: C = None
        self.txt = txt

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

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

j = A("j")
d = B("d")
m = C("m")
k = A("k")

j.r = m
j.p = m
d.u = m
m.q = d
k.r = m
k.p = m
assert m.q.u.q.txt == "d"