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

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

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

class D:
    def __init__(self, txt: str):
        self.p: A = None
        self.u: A = None
        self.txt = txt

k = A("k")
m = B("m")
b = C("b")
d = D("d")
g = C("g")
c = B("c")
a = D("a")
e = C("e")

k.r = c
m.x = c
b.q = g
d.p = k
d.u = k
g.q = b
c.x = m
a.p = k
a.u = k
e.q = b
assert g.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.p: A = None
        self.u: A = None
        self.txt = txt

k = A("k")
m = B("m")
b = C("b")
d = D("d")
g = C("g")
c = B("c")
a = D("a")
e = C("e")

k.r = c
m.x = c
b.q = g
d.p = k
d.u = k
g.q = b
c.x = m
a.p = k
a.u = k
e.q = b
assert g.q.q.q.q.txt == "g"