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

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

l = A("l")
h = B("h")
i = A("i")
a = B("a")
f = A("f")
g = B("g")
d = A("d")

l.q = f
l.o = f
h.r = f
i.q = l
i.o = f
a.r = d
f.q = l
f.o = i
g.r = d
d.q = f
d.o = i
assert i.q.o.q.o.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: A = None
        self.txt = txt

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

l = A("l")
h = B("h")
i = A("i")
a = B("a")
f = A("f")
g = B("g")
d = A("d")

l.q = f
l.o = f
h.r = f
i.q = l
i.o = f
a.r = d
f.q = l
f.o = i
g.r = d
d.q = f
d.o = i
assert i.q.o.q.o.o.q.txt == "l"