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

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

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

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

n = A("n")
c = B("c")
a = C("a")
d = D("d")
m = D("m")
l = B("l")
g = A("g")
k = B("k")

n.t = c
n.x = g
c.v = g
a.v = g
d.w = a
m.w = a
l.v = n
g.t = l
g.x = n
k.v = n
assert g.t.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.x: A = None
        self.txt = txt

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

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

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

n = A("n")
c = B("c")
a = C("a")
d = D("d")
m = D("m")
l = B("l")
g = A("g")
k = B("k")

n.t = c
n.x = g
c.v = g
a.v = g
d.w = a
m.w = a
l.v = n
g.t = l
g.x = n
k.v = n
assert g.t.v.t.txt == "c"