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

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

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

m = A("m")
f = B("f")
d = C("d")
b = A("b")
l = A("l")
c = A("c")

m.w = d
m.p = f
m.r = c
f.r = c
f.o = b
d.q = f
d.w = m
b.w = d
b.p = f
b.r = l
l.w = d
l.p = f
l.r = b
c.w = d
c.p = f
c.r = l
assert b.p.r.r.w.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.p: B = None
        self.r: A = None
        self.txt = txt

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

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

m = A("m")
f = B("f")
d = C("d")
b = A("b")
l = A("l")
c = A("c")

m.w = d
m.p = f
m.r = c
f.r = c
f.o = b
d.q = f
d.w = m
b.w = d
b.p = f
b.r = l
l.w = d
l.p = f
l.r = b
c.w = d
c.p = f
c.r = l
assert b.p.r.r.w.q.r.txt == "c"