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

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

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

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

b = A("b")
h = B("h")
c = C("c")
e = D("e")
m = C("m")
g = D("g")

b.q = g
b.r = e
h.r = b
h.o = c
h.q = c
c.v = h
c.o = h
c.s = m
e.u = b
m.v = h
m.o = h
m.s = c
g.u = b
assert m.s.s.s.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.r: D = None
        self.txt = txt

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

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

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

b = A("b")
h = B("h")
c = C("c")
e = D("e")
m = C("m")
g = D("g")

b.q = g
b.r = e
h.r = b
h.o = c
h.q = c
c.v = h
c.o = h
c.s = m
e.u = b
m.v = h
m.o = h
m.s = c
g.u = b
assert m.s.s.s.s.v.txt == "h"