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

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

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

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

f = A("f")
e = B("e")
g = C("g")
j = D("j")
d = D("d")
l = C("l")
m = A("m")
h = B("h")

f.y = e
f.q = j
f.v = d
e.z = m
g.t = l
j.x = g
d.x = g
l.t = g
m.y = e
m.q = d
m.v = d
h.z = f
assert g.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: D = None
        self.v: D = None
        self.txt = txt

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

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

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

f = A("f")
e = B("e")
g = C("g")
j = D("j")
d = D("d")
l = C("l")
m = A("m")
h = B("h")

f.y = e
f.q = j
f.v = d
e.z = m
g.t = l
j.x = g
d.x = g
l.t = g
m.y = e
m.q = d
m.v = d
h.z = f
assert g.t.t.t.t.t.txt == "l"