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

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

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

b = A("b")
j = B("j")
a = C("a")
m = C("m")
k = B("k")
f = A("f")

b.z = j
j.r = b
j.o = k
a.q = j
a.p = j
m.q = j
m.p = k
k.r = f
k.o = j
f.z = j
assert a.p.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

b = A("b")
j = B("j")
a = C("a")
m = C("m")
k = B("k")
f = A("f")

b.z = j
j.r = b
j.o = k
a.q = j
a.p = j
m.q = j
m.p = k
k.r = f
k.o = j
f.z = j
assert a.p.r.z.r.txt == "b"