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

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

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

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

d.r = c
d.p = j
c.u = j
c.q = d
j.p = b
j.y = b
b.p = j
b.y = j
assert c.u.y.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: C = None
        self.txt = txt

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

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

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

d.r = c
d.p = j
c.u = j
c.q = d
j.p = b
j.y = b
b.p = j
b.y = j
assert c.u.y.p.txt == "j"