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

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

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

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

class E:
    def __init__(self, txt: str):
        self.r: B = None
        self.v: C = None
        self.y: B = None
        self.t: B = None
        self.o: B = None
        self.txt = txt

m = A("m")
b = B("b")
j = C("j")
n = D("n")
d = E("d")
f = C("f")

m.r = n
m.o = f
b.r = m
j.t = f
j.z = f
j.q = b
n.r = b
n.p = b
d.r = b
d.y = b
d.t = b
d.o = b
d.v = j
f.t = j
f.z = j
f.q = b
assert m.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.o: C = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.r: B = None
        self.v: C = None
        self.y: B = None
        self.t: B = None
        self.o: B = None
        self.txt = txt

m = A("m")
b = B("b")
j = C("j")
n = D("n")
d = E("d")
f = C("f")

m.r = n
m.o = f
b.r = m
j.t = f
j.z = f
j.q = b
n.r = b
n.p = b
d.r = b
d.y = b
d.t = b
d.o = b
d.v = j
f.t = j
f.z = j
f.q = b
assert m.r.p.r.txt == "m"