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

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

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

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

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

h.t = k
b.q = k
b.v = m
g.r = m
m.v = b
m.o = k
m.w = f
m.y = h
f.q = h
f.v = m
k.t = h
assert b.v.o.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.txt = txt

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

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

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

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

h.t = k
b.q = k
b.v = m
g.r = m
m.v = b
m.o = k
m.w = f
m.y = h
f.q = h
f.v = m
k.t = h
assert b.v.o.t.txt == "h"