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

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

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

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

c = A("c")
a = B("a")
d = C("d")
b = D("b")
g = B("g")
l = C("l")
k = D("k")
j = A("j")
f = B("f")

c.q = l
a.q = b
d.t = l
d.q = l
b.r = l
g.q = k
l.t = d
l.q = d
k.r = l
j.q = d
f.q = k
assert d.t.t.t.q.q.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

c = A("c")
a = B("a")
d = C("d")
b = D("b")
g = B("g")
l = C("l")
k = D("k")
j = A("j")
f = B("f")

c.q = l
a.q = b
d.t = l
d.q = l
b.r = l
g.q = k
l.t = d
l.q = d
k.r = l
j.q = d
f.q = k
assert d.t.t.t.q.q.t.q.txt == "l"