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

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

l = A("l")
k = B("k")
c = B("c")
g = A("g")
e = B("e")
b = A("b")
a = A("a")
i = B("i")

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

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

l = A("l")
k = B("k")
c = B("c")
g = A("g")
e = B("e")
b = A("b")
a = A("a")
i = B("i")

l.q = i
l.r = c
k.p = c
c.p = k
g.q = c
g.r = i
e.p = k
b.q = e
b.r = e
a.q = k
a.r = c
i.p = e
assert i.p.p.p.p.txt == "k"