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

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

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

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

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

a.t = g
a.v = b
b.t = h
g.p = b
g.y = b
g.t = m
g.r = m
h.q = a
m.t = g
m.v = b
assert a.t.t.v.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.v: B = None
        self.txt = txt

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

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

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

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

a.t = g
a.v = b
b.t = h
g.p = b
g.y = b
g.t = m
g.r = m
h.q = a
m.t = g
m.v = b
assert a.t.t.v.t.q.txt == "a"