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

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

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

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

i = A("i")
m = B("m")
f = C("f")
h = D("h")
b = D("b")
n = D("n")
a = D("a")

i.q = f
i.t = m
m.y = i
m.u = i
m.z = f
m.r = f
f.r = m
h.t = a
b.t = n
n.t = b
a.t = n
assert h.t.t.t.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.t: B = None
        self.txt = txt

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

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

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

i = A("i")
m = B("m")
f = C("f")
h = D("h")
b = D("b")
n = D("n")
a = D("a")

i.q = f
i.t = m
m.y = i
m.u = i
m.z = f
m.r = f
f.r = m
h.t = a
b.t = n
n.t = b
a.t = n
assert h.t.t.t.t.t.t.t.txt == "b"