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

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

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

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

b = A("b")
m = B("m")
f = C("f")
c = D("c")
n = B("n")
i = A("i")

b.r = c
m.q = f
m.o = i
m.s = b
f.x = c
f.q = c
f.r = i
f.p = m
c.q = n
c.r = m
n.q = f
n.o = b
n.s = i
i.r = c
assert i.r.q.q.p.q.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

b = A("b")
m = B("m")
f = C("f")
c = D("c")
n = B("n")
i = A("i")

b.r = c
m.q = f
m.o = i
m.s = b
f.x = c
f.q = c
f.r = i
f.p = m
c.q = n
c.r = m
n.q = f
n.o = b
n.s = i
i.r = c
assert i.r.q.q.p.q.r.txt == "i"