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

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

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

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

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

g.y = h
m.y = h
m.t = l
c.x = h
c.v = b
b.q = m
b.o = m
l.q = h
l.o = m
h.y = m
h.t = b
assert m.y.t.o.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

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

g.y = h
m.y = h
m.t = l
c.x = h
c.v = b
b.q = m
b.o = m
l.q = h
l.o = m
h.y = m
h.t = b
assert m.y.t.o.t.q.t.txt == "b"