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

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

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

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

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

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

g.o = j
j.p = c
j.o = c
l.p = c
l.o = c
i.p = c
i.o = g
b.p = c
b.o = g
c.o = j
k.p = g
k.o = g
assert i.o.o.o.o.p.o.txt == "j"