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

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

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

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

f = A("f")
l = B("l")
d = C("d")
k = D("k")
c = A("c")

f.o = l
l.v = d
d.t = l
d.x = k
d.y = k
d.q = f
k.y = l
c.o = l
assert d.y.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

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

f = A("f")
l = B("l")
d = C("d")
k = D("k")
c = A("c")

f.o = l
l.v = d
d.t = l
d.x = k
d.y = k
d.q = f
k.y = l
c.o = l
assert d.y.y.v.txt == "d"