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

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

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

b = A("b")
l = B("l")
d = C("d")
k = C("k")
c = B("c")
h = A("h")
n = C("n")
m = A("m")

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

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

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

b = A("b")
l = B("l")
d = C("d")
k = C("k")
c = B("c")
h = A("h")
n = C("n")
m = A("m")

b.q = n
b.r = n
l.q = d
l.t = b
l.u = n
d.v = k
k.v = n
c.q = n
c.t = b
c.u = d
h.q = d
h.r = n
n.v = d
m.q = k
m.r = n
assert n.v.v.v.v.txt == "d"