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

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

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

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

m = A("m")
n = B("n")
h = C("h")
k = D("k")
d = C("d")
c = A("c")
a = B("a")

m.u = h
n.r = k
n.q = k
h.t = m
k.t = d
d.t = m
c.u = h
a.r = k
a.q = k
assert h.t.u.t.u.t.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

m = A("m")
n = B("n")
h = C("h")
k = D("k")
d = C("d")
c = A("c")
a = B("a")

m.u = h
n.r = k
n.q = k
h.t = m
k.t = d
d.t = m
c.u = h
a.r = k
a.q = k
assert h.t.u.t.u.t.u.txt == "h"