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

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

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

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

c = A("c")
d = B("d")
l = C("l")
h = D("h")
g = B("g")
m = D("m")
k = C("k")

c.o = l
d.r = m
d.o = g
l.r = c
l.q = c
l.t = c
l.z = d
h.r = m
g.r = m
g.o = d
m.r = h
k.r = c
k.q = c
k.t = c
k.z = d
assert h.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

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

c = A("c")
d = B("d")
l = C("l")
h = D("h")
g = B("g")
m = D("m")
k = C("k")

c.o = l
d.r = m
d.o = g
l.r = c
l.q = c
l.t = c
l.z = d
h.r = m
g.r = m
g.o = d
m.r = h
k.r = c
k.q = c
k.t = c
k.z = d
assert h.r.r.r.txt == "m"